package com.antcom.antread.antreadmodules.antreadsystem.log.service.impl;

import com.alibaba.fastjson.JSON;
import com.antcom.antread.antreadmodules.antreadsystem.log.dao.OperationLogMapper;
import com.antcom.antread.antreadmodules.antreadsystem.log.service.ILogService;
import com.antcom.antread.api.domain.OperationLog;
import com.antcom.antread.common.core.baseRest.domain.PageDevice;
import com.antcom.antread.common.core.serialize.JSONSerialize;
import com.antcom.antread.common.core.text.UUIDUtil;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.List;

/**
 * log:实现类
 *
 * @Author 中国蚂蚁技术有限公司
 * @create 2020/12/25 22:19
 */
@Service
public class LogServiceImpl implements ILogService {

    @Inject
    private OperationLogMapper operationLogMapper;

    @Override
    public void save(OperationLog operationLog) {
        operationLog.setOperId(UUIDUtil.getUUIDRow());
        System.out.println(JSON.toJSONString(operationLog));
        operationLogMapper.save(operationLog);
    }

    @Override
    public OperationLog findOne(String operId) {
        return operationLogMapper.findOne(operId);
    }

    @Override
    public void deleteById(String operId) {
        operationLogMapper.deleteById(operId);
    }

    @Override
    public PageDevice findAllPage(String param) {
        PageDevice pageDevice = JSONSerialize.deserializeJackSon(param, PageDevice.class);
        String sortMap = pageDevice.getSortMap().get("sortMap");
        int startNum = Integer.parseInt(pageDevice.getStartPageNum());
        int endNum = Integer.parseInt(pageDevice.getPageSize());

        List<OperationLog> operationLogList = operationLogMapper.findAllPage(sortMap, startNum, endNum);
        pageDevice.setList(operationLogList);
        pageDevice.setTotalCount(String.valueOf(operationLogList.size()));
        return pageDevice;
    }


}
